type IFilter = (value: any) => string;

export class TemplateFilters {
    private filters: Record<string, IFilter> = {};

    filter(tag: string, fn: IFilter) {
        tag = String(tag).toLocaleLowerCase();

        this.filters[tag] = fn;
        return this;
    }

    format(tag: string, value: any) {
        try {
            tag = String(tag).toLocaleLowerCase();

            const fn = this.filters[tag];
            if (fn) {
                return fn(value);
            }
            return value;
        } catch {
            return value;
        }
    }
}
